package flatlandRPG;

import java.awt.geom.Rectangle2D;
import java.awt.Polygon;
import org.lwjgl.util.Color;
import org.lwjgl.util.vector.Vector2f;

// -------------------------------------------------------------------------
/**
 * Represents a solid building that the player cannot walk through.
 *
 * @author evant
 * @author trev
 * @version Apr 17, 2011
 */
public class Building
    extends GLPolygon
    implements ISolid
{
    // ----------------------------------------------------------
    /**
     * Create a new Building object.
     *
     * @param points
     *            the points that define the vertices of the building
     */
    public Building(Vector2f... points)
    {
        super(points);
    }


    /**
     * Create a new Building object.
     *
     * @param points
     *            the points that define the vertices of the building
     */
    public Building(Float... points)
    {
        super(points);
        setColor(new Color(255, 255, 255));
    }


    /**
     * Create a new Building object that allows changing of the default color
     *
     * @param points
     *            the points that define the vertices of the building
     * @param red
     *            the red color value
     * @param green
     *            the green color value
     * @param blue
     *            the blue color value
     */
    public Building(int red, int green, int blue, Float... points)
    {
        super(points);
        setColor(new Color(red, green, blue));
    }


    @Override
    public boolean collidedWith(IMoveable object)
    {
        int mult = 100;

        Polygon polygon = new Polygon();
        for (Vector2f point : points)
        {
            polygon.addPoint(
                (int)((point.getX() + getX()) * mult),
                (int)((point.getY() + getY()) * mult));
        }
        Rectangle2D box = object.getBounds();
        double x = box.getX() * mult;
        double y = box.getY() * mult;
        double width = box.getWidth() * mult;
        double height = box.getHeight() * mult;

        return polygon.intersects(x, y, width, height);
    }
}
